﻿using System;
using System.ComponentModel;
using System.Threading.Tasks;

namespace UpdateApp.Download
{
    /// <summary>
    /// 下载回调
    /// </summary>
    internal interface IDownloadCallback
    {
        /// <summary>
        /// 下载数据回调接收
        /// </summary>
        internal Task ReceiveDownloadDataAsync(DownloadDataDto data);
    }

    /// <summary>
    /// 下载状态
    /// </summary>
    internal enum DownloadType
    {
        /// <summary>
        /// 进行中
        /// </summary>
        [Description("进行中")]
        Process = 0,

        /// <summary>
        /// 完成
        /// </summary>
        [Description("完成")]
        Complete = 1,

        ///// <summary>
        ///// 失败
        ///// </summary>
        //[Description("失败")]
        //Fail = 2,
    }

    /// <summary>
    /// 下载数据模型
    /// </summary>
    internal class DownloadDataDto
    {
        /// <summary>
        /// 数据,下载完成或失败为null
        /// </summary>
        public byte[]? Data { get; set; }

        /// <summary>
        /// 数据总长度,-1:服务端未返回总长度
        /// </summary>
        public long Total { get; set; }

        /// <summary>
        /// 文件名称
        /// </summary>
        public string? FileName { get; set; }

        /// <summary>
        /// 下载状态
        /// </summary>
        public DownloadType DownloadType { get; set; } = DownloadType.Process;

        /// <summary>
        /// 进度数据 0-100
        /// </summary>
        public decimal Progress { get; set; }

        /// <summary>
        /// 是否是第一个数据包
        /// </summary>
        public bool IsFirstPacket { get; set; }

        ///// <summary>
        ///// 异常
        ///// </summary>
        //public Exception Error { get; set; }
    }
}
